<?php
	if (!empty($this->validationErrors) && !empty($this->validationErrors['Employee']))
	{
		echo "<div style=\"padding-left: 165px; color: red; padding-bottom: 5px;\">\n\t<ul>";
		foreach ($this->validationErrors['Employee'] as $key => $value) {
			echo "\t\t<li>$value</li>";
		}
		echo "\t</ul>\n</div>";
	}
//	echo $this->validationErrors['Employee']['firstname']
?>
<div id="navi_bar">
	<div style="width: 250px; text-align:left; float:left; font-size: 10pt; font-family: Tahoma">
    	<strong>Danh sách nhân sự</strong>
	</div>
    <div style="width: 150px; text-align:right; float:right;">
		<a href="/users/add"><img id="btnadd" src="/img/add.gif" style="border: none" title="Thêm mới" /></a>&nbsp;
        <img id="btndelete" src="/img/delete.gif" title="Xóa bỏ" style="cursor: pointer" />&nbsp;
        <img id="btnSelectAll" src="/img/checkall.gif" title="Chọn tất cả" style="cursor: pointer" />&nbsp;
        <img id="btnUnSelectAll" src="/img/uncheckall.gif" title="Hủy chọn tất cả" />&nbsp;
        <img id="btnDisSelect" src="/img/checkdis.gif" title="Đảo chọn" />
	</div>
    <div style="clear:both"></div>
</div>
<div>
<?php if(empty($users)): ?>
	<font color="red">Không có dữ liệu</font>
<?php else: ?>
<?php
	$iSTT = 1;
?>
	<table id="tableEmployees" class="tablesorter" style="margin-top:1px" cellpadding="0" cellspacing="0">
		<thead>
          <tr>
             <th style="border-left: 1px solid gray; width:30px;" align="center">#</th>
             <th style="width:120px;" align="center">Tên truy cập</th>
			 <th style="width:*;" align="center">Họ và Tên</th>
			 <th style="width:120px;" align="center">Email</th>
             <th style="width:110px;" align="center">Active</th>
			 <th style="width:60px;" align="center">Action</th>
          </tr>
		</thead>
		<tbody style="text-align:left;">
          <?php foreach ($users as $user): ?>
             <tr>
                <td align="right" style="border-left: 1px solid gray"><?=$iSTT?></td>
				<td><?=$user['User']['username'] ?></td>
				<td align="right"><?=$user['Employee']['firstname'] ?> <?=$user['Employee']['middlename'] ?> <?=$user['Employee']['lastname'] ?></td>
				<td align="right"><?=$user['Employee']['email'] ?></td>
                <td align="right">
<?php
				if ($user['User']['status'] == 0) {
					echo "Không hoạt động";
				} elseif ($user['User']['status'] == 1) {
					echo "Hoạt động";
				} else {
					echo "Không xác định";
				}
?>
				</td>
				<td align="right">
					<span class="editItems"><a set="yes" href="/users/edit/<?=$user['User']['id']?>" title="Cập nhật"><img src="/img/edit.png" class="editIterm" style="border: none" /></a></span>
					<span class="chkItems"><input type="checkbox" name="chk_delete" id="chk_<?=$user['User']['id'] ?>" /></span>
				</td>
             </tr>
			 <?php $iSTT++; ?>
          <?php endforeach; ?>
		</tbody>
	</table>
<?php endif; ?>
</div>
<div id="mainpaging">
	<div style="width: 300px; text-align:left; float:left; font-size: 11px; font-family: Tahoma;padding-top: 4px; padding-bottom: 2px;">Tổng số <?=$countPage?> trang - <?=$countAll?> nhân sự</div>
    <div style="width: 300px; text-align:right; float:right; padding-bottom: 2px;">
		<span class="num" id="num_10">10</span>
		<span class="num" id="num_20">20</span>
		<span class="num" id="num_30">30</span>
		<span class="num" id="num_40">40</span>
<?php
	if ($countPage>1)
	{
		if ($curpage>1)
		{
			echo "<img class=\"paging\" style=\"cursor: pointer;\" src=\"/img/pg-first.gif\" title=\"Trang đầu\" />";
			echo "<img class=\"paging\" id=\"page_" . ($curpage-1) . "\" style=\"cursor: pointer;\" src=\"/img/pg-prev.gif\" title=\"Trang trước\" />";
		}
		else
		{
			echo "<img class=\"paging\" style=\"cursor: pointer;\" src=\"/img/pg-first.gif\" title=\"Trang đầu\" />";
			echo "<img class=\"paging\" style=\"cursor: pointer;\" src=\"/img/pg-prev.gif\" title=\"Trang trước\" />";
		}
		for ($i=5;$i>0;$i--)
		{
			if (($curpage -$i) > 0)
				echo "<span class=\"paging\" id=\"page_".($curpage - $i)."\">".($curpage - $i)."</span>";
		}
		echo "<span class=\"pageselected\" id=\"page_".$curpage."\">".($curpage - $i)."</span>";
		for ($i=1;$i<5;$i++)
		{
			if (($curpage + $i) <= $countPage)
				echo "<span class=\"paging\" id=\"page_".($curpage + $i)."\">".($curpage + $i)."</span>";
		}
		
		if ($curpage<$countPage)
		{
			echo "<img class=\"paging\" id=\"page_" . ($curpage+1) . "\" style=\"cursor: pointer;\" src=\"/img/pg-next.gif\" title=\"Trang tiếp\" />";
			echo "<img class=\"paging\" id=\"page_" . $countPage . "\" style=\"cursor: pointer;\" src=\"/img/pg-last.gif\" title=\"Trang cuối\" />";
		}
		else
		{
			echo "<img class=\"paging\" style=\"cursor: pointer;\" src=\"/img/pg-next.gif\" title=\"Trang tiếp\" />";
			echo "<img class=\"paging\" style=\"cursor: pointer;\" src=\"/img/pg-last.gif\" title=\"Trang cuối\" />";
		}
	}
	else
	{
//		echo "&nbsp;";
	}
?>
	</div>
    <div style="clear:both"></div>
</div>